package Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import pojo.student;
public class studentDao {

    //这里封装增删改查操作
    private static final String INSERT_STUDENT_SQL="INSERT INTO student(id,name,age,sex,className) VALUES(?,?,?,?,?)";
     public student studentObj=new student();
    public void add(student studentObj){
        System.out.println("添加学生");

        try (
                //  weatherDao.deleteWeather();------------这里面的方法在try---在里面和----在外面有什么区别
                Connection connection = DatabaseConnection.getConnection();
                PreparedStatement preparedStatement = connection.prepareStatement(INSERT_STUDENT_SQL)) {
            preparedStatement.setInt(1, studentObj.getId());
            preparedStatement.setString(2, studentObj.getName());
            preparedStatement.setInt(3, studentObj.getAge());
            preparedStatement.setString(4, studentObj.getSex());
            preparedStatement.setString(5, studentObj.getClassName());
            System.out.println(preparedStatement + "到这了");
            int rowinserted = preparedStatement.executeUpdate();
            if (rowinserted > 0) {
                System.out.println("插入学生数据成功");}
            else {
                System.out.println("未找到指定的学生记录");
            }
        } catch (SQLException e) {

            e.printStackTrace();
        }
    }
    //删除
    public void delete(){
        System.out.println("删除学生");
        return;
        }

        public void update(){
        System.out.println("修改学生");
        return;}


        public void search(){
        System.out.println("查询学生");
        return;
        }



        }




